<?php $header=$this->action('ZfcAdmin\Controller\AdminController', 'headerAction');
	  $baseUrl = $header->headerarray['baseUrl'];
?>
<?php if(isset($_SESSION['admin'])){?>
<html>
	<body>		
		<?php if(isset($_GET['paper_cir_id']) && $_GET['paper_cir_id']!=""){?>
		<h3>Edit Paper:</h3>
		<?}else{?>
		<h3>Add Paper:</h3>
		<?}?>
		<center>
			<form id="paper_form" name="paper_form" method="post" action="">
					<div>
						Districts:<select id="districts" name="districts" onChange="return getAdminDistrictAreas('district');">
							<option value="">Select a district</option>
						<? if($this->list_districts->count()>0){ foreach($this->list_districts as $district){ 
						  if($this->get_paper->district_id==$district->district_id){?>
							<option value="<? echo $district->district_id;?>" selected="selected"><? echo $district->district_name;?></option>
						  <? } else if($_GET['dist_id']==$district->district_id){?>
							<option value="<? echo $district->district_id;?>" selected="selected"><? echo $district->district_name;?></option>
						  <?}else {?>
							<option value="<? echo $district->district_id;?>"><? echo $district->district_name;?></option>
						  <?}?>
						<?}}else{?>
							<option value="">No districts</option>
						<?}?>
						</select><br/>	<br/><br/>
						Area:<select id="areas" name="areas" onChange="return getAdminAreaBasedLocations('location');">
							<option value="">Select a area</option>						
						</select><br/>	<br/><br/>	
						Locations:<select id="location" name="location">
							<option value="">Select a location</option>						
						</select><br/>	<br/><br/>						
						Paper:<select id="paper" name="paper">
							<option value="">Select a paper</option>
						<? if($this->paper_list->count()>0){ foreach($this->paper_list as $papers){ 
						   if($this->get_paper->paper_id==$papers->paper_id){?>
							<option value="<? echo $papers->paper_id;?>" selected="selected"><? echo $papers->m_paper_name;?></option>
						   <?}elseif($_GET['paper_id']==$papers->paper_id){?>
							<option value="<? echo $papers->paper_id;?>" selected="selected"><? echo $papers->m_paper_name;?></option>
						   <?}else{?>
							<option value="<? echo $papers->paper_id;?>"><? echo $papers->m_paper_name;?></option>
						   <?}?>
						<?}}else{?>
							<option value="">No Papers</option>
						<?}?>
						</select><br/>	<br/><br/>	
						<? if(isset($this->get_paper->paper_cir_id) && $this->get_paper->paper_cir_id!=""){?>
							Paper: <input type="text" id="paper_name" name="paper_name" value="<? echo $this->get_paper->paper_name;?>"><br/><br/>
							Count Paper: <input type="text" id="cnt_paper" name="cnt_paper" value="<? echo $this->get_paper->count_paper;?>"><br/><br/>							
							Amount for paper : <input type="text" id="amt_paper" name="amt_paper" value="<? echo $this->get_paper->amount_paper;?>">							
						<?}else{?>
						<div id="subdiv">			
							<div id ="txtdiv0">
								Paper:<input type="text" id="paper_name" name="paper_name[]"><br/><br/>
								Count Paper:<input type="text" id="cnt_paper" name="cnt_paper[]"><br/><br/>
								Amount for paper : <input type="text" id="amt_paper" name="amt_paper[]">
								<input type="button" onclick="addTextBox()" id="add0" value="+">
								<input type="button" onclick="removeTextBox()" id="remove0" style="display:none;" value="-"><br/>
							</div>	
						</div>
						<?}?>
					</div>
				<br/><br/>				
					<a href="<? echo $baseUrl.'admin/population-paper'?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btn_paper" name="btn_paper" value="Save" onclick="return add_paper()">
					<input type="hidden" id="hid_paper" name="hid_paper" value="<?  if(isset($this->get_paper->paper_cir_id) && $this->get_paper->paper_cir_id!=""){ echo $this->get_paper->paper_cir_id;}else{}?>">
					<input type="hidden" id="addd_url_dist_id" name="addd_url_dist_id" value="<?  if(isset($_GET['dist_id']) && $_GET['dist_id']!=""){ echo $_GET['dist_id'];}else{}?>">
					<input type="hidden" id="add_url_area_id" name="add_url_area_id" value="<?  if(isset($_GET['area_id']) && $_GET['area_id']!=""){ echo $_GET['area_id'];}else{}?>">
					<input type="hidden" id="add_url_location_id" name="add_url_location_id" value="<?  if(isset($_GET['location_id']) && $_GET['location_id']!=""){ echo $_GET['location_id'];}else{}?>">
					<input type="hidden" id="add_url_paper_id" name="add_url_paper_id" value="<?  if(isset($_GET['paper_id']) && $_GET['paper_id']!=""){ echo $_GET['paper_id'];}else{}?>">
			</form>
		</center>
	</body>
</html>
<script>
$( document ).ready(function() {
	
	<?php  if(isset($_GET['dist_id']) && $_GET['dist_id']!=""){?>	
			getAdminDistrictAreas('district');
	<?php } if(isset($_GET['dist_id']) && $_GET['dist_id']!="" && isset($_GET['area_id']) && $_GET['area_id']!=""){?>
			getAdminAreaBasedLocations('locations');
	<?php }?>
});
var i=0;
function addTextBox(){
	i++;
	$('#subdiv').append('<br/><div id = "txtdiv'+i+'">Paper:<input type="text" id="paper_name'+i+'"  name="paper_name[]"><br/><br/>count Paper:<input type="text" id="cnt_paper'+i+'"  name="cnt_paper[]"><br/><br/>Amount for paper:<input type="text" id="amt_paper'+i+'"  name="amt_paper[]">&nbsp;&nbsp;<input type="button" onclick="addTextBox()" id="add'+i+'" value="+"><input type="button" onclick="removeTextBox()" id="remove'+i+'" value="-"></div>');
	var j = i - 1;
	$('#remove'+j).show();
	$('#remove'+i).hide();
	$('#add'+j).hide();
	
}
function removeTextBox(){
	$('#txtdiv'+i).remove();
	i--;
	$('#remove'+i).hide();
	$('#add'+i).show();
}
</script>
<? } else {?>
<script>
	window.location=ADMIN_BASE_URL+'admin';
</script>
<?}?>